package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    @Insert("insert into orders( number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) VALUES " +
            "(#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod},#{payStatus},#{amount},#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{rejectionReason},#{cancelTime},#{estimatedDeliveryTime},#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Orders order);

    @Select("select * from sky_take_out.orders where number=#{orderNumber} ")
    Orders getByNumberAndUserId(String orderNumber);

    void update(Orders orders);

    @Select("select * from sky_take_out.order_detail where id=#{id}")
    List<OrderDetail> getByUserId(Long id);

    @Select("select * from sky_take_out.orders where id=#{id}")
    Orders getByOrderId(Long id);

    OrderVO getOrderById(Long id);

    List<OrderVO> historyOrdersPage(OrdersPageQueryDTO ordersPageQueryDTO);
//管理端分页查询

   Page<Orders> adminPage(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from sky_take_out.orders where status=#{status}")
    Integer selectCount(Integer status);

    Double sumByMap(Map map);

    Integer countByMap(Map map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}

